import Vue from 'vue'
import App from './App'
import router from './router'
import $http from './api/index.js'
import VueLazyLoad from 'vue-lazyload'
import Vuex from 'vuex'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import MintUi from 'mint-ui'
import YDUI from 'vue-ydui';
import 'mint-ui/lib/style.css'
import 'vue-ydui/dist/ydui.rem.css';
import { userInfo } from './api'
require('swiper/dist/css/swiper.css')
require('./assets/css/base.css');
Vue.use(VueAwesomeSwiper)
Vue.use(MintUi)
Vue.use(Vuex)
Vue.use(YDUI);
Vue.use(VueLazyLoad, {
	error: require('./assets/images/err.png'),
	loading: require('./assets/images/loading.gif'),
})

//const whiteList = ['/login', '/test', '/home', '/register', '/category', '/category/*']
const whiteList = []
router.beforeEach(function(to, from, next) {
	window.localStorage.muban = 2;
	userInfo(localStorage.Authorization, function(res) {
		if(res.code == 101 || res.code == 403) {
			let zhengzestr = '/' + to.path.split('/')[1]
			if(whiteList.indexOf(zhengzestr) == -1) {
				next()
			} else {
				next('/login')
			}
		} else {
			next()
		}
	}, function(res) {
		//失败返回的
	})
})
Vue.config.productionTip = false
Vue.prototype.$http = $http
Vue.prototype.root = $http.root
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
})